import $ from 'webpack-zepto'

export default {
  inserted (el, binding, vNode) {
    let siblingsHeight = 0
    const resize = function () {
      let _siblingsHeight = 0
      const siblings = $(el).siblings()
      siblings.each(function () {
        _siblingsHeight += this.clientHeight
      })
      if (_siblingsHeight !== siblingsHeight) {
        siblingsHeight = _siblingsHeight
        el.style.height = `calc(100% - ${siblingsHeight}px)`
      }
    }
    el.style.height = `calc(100% - ${siblingsHeight}px)`
    el.parentNode.addEventListener('DOMSubtreeModified', resize)
    // window.addEventListener('resize', resize)
  }
}
